package com.coffee.ws;

import com.coffee.ws.command.CoffeeCommandEnum;
import com.coffee.ws.handler.CoffeeCloseHandler;
import com.coffee.ws.handler.CoffeeConnectHandler;
import com.coffee.ws.handler.HandlerMapping;
import com.coffee.ws.handler.CoffeeUserValidHandler;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author: songkui
 * @since: 2023/2/23 10:30
 */
@Slf4j
@NoArgsConstructor
public class CoffeeWebSocketBuilder {

    public static CoffeeWebSocketBuilder builder(){
        return new CoffeeWebSocketBuilder();
    }

    public CoffeeWebSocketBuilder connectHandler(CoffeeConnectHandler connectHandler) {
        HandlerMapping.initializeConnectHandler(connectHandler);
        return this;
    }

    public CoffeeWebSocketBuilder closeHandler(CoffeeCloseHandler closeHandler) {
        HandlerMapping.initializeCloseHandler(closeHandler);
        return this;
    }

    public CoffeeWebSocketBuilder userValidHandler(CoffeeUserValidHandler userValidHandler) {
        HandlerMapping.initializeUserValidHandler(userValidHandler);
        return this;
    }


    public CoffeeWebSocketBuilder initialize(Map<Integer, CoffeeCommandEnum> commandEnumMap, String handlerPackagePath) throws Exception {
        WebSocketInitialize.initializeCommandModel(commandEnumMap);
        WebSocketInitialize.initializeHandlerMapping(handlerPackagePath, commandEnumMap);
        return this;
    }

    public void start() {
        log.info("Coffee WebSocket is start");
    }


}
